<template>
	<view class="container">
		<view class="title">
			选择{{data.state==0?"登录":"忘记密码"}}的账号
		</view>
		<view class="mobile">
			您的手机号<text>{{data.form.mobile}}</text>绑定了多个账号,请选择需要{{data.state==0?"登录":"忘记密码"}}的账号
		</view>
		<view class="list">
			<view class="item" v-for="item in data.list" :key="item.ID" @click="login(item.project)">
				<view class="head">
					<image :src="item.head||$defaultAvatar" mode=""></image>
				</view>
				<view class="right">
					<view class="box">
						<view class="mobiles">
							{{item.nikename}}{{item.mobile}}
						</view>
						<text class="project">
							{{item.project_name||item.project}}
						</text>
					</view>
					<uni-icons type="right" size="20"></uni-icons>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {ref,reactive,getCurrentInstance} from "vue";
	import {onLoad,onShow,onPullDownRefresh,onReachBottom} from "@dcloudio/uni-app";
	const { proxy } = getCurrentInstance();
	const data = reactive({
		list:[],
		form:{},
		state:0,//0 登录 1 忘记密码
	})
	onLoad((option)=>{
		data.list=proxy.$store.state.data.list
		data.form=proxy.$store.state.data.form
		data.state=proxy.$store.state.data.state

	})
	onShow(()=>{
	})
	onPullDownRefresh(()=> {
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		})
	onReachBottom(()=>{
		console.log('onReachBottom')
	})
	function login (project){
		if(data.state==0){
			proxy.$request({
				url: `api/login/`,
				method: 'post',
				data:{
					mobile:data.form.mobile,
					password:data.form.password,
					project:project
				},
				success(res) {
					uni.showToast({
						icon:"none",
						title:res.errmsg
					})
					if(res.errno==0){
						uni.setStorageSync("userInfo",res.data)
						uni.switchTab({
							url:"/pages/personal/index"
						})
					}
				}
			})
		}else{
			proxy.$store.state.data={
				mobile:data.form.mobile,
				password:data.form.password,
				re_password:data.form.re_password,
				smg:data.form.smg,
				project:project,
			}
			uni.navigateBack()
		}


	}
</script>

<style lang="scss">
	page{
		background-color: #fff;
	}
	.container{
		padding: 30upx;
		.title{
			font-size: 24px;
			font-family: Source Han Sans SC, Source Han Sans SC-Bold;
			font-weight: 700;
			text-align: left;
			color: #000000;
			line-height: 36px;
			letter-spacing: 0.48px;
		}
		.mobile{
			font-size: 13px;
			font-family: Source Han Sans SC, Source Han Sans SC-Regular;
			font-weight: 400;
			text-align: left;
			color: #999999;
			line-height: 24px;
			letter-spacing: 0.26px;
			text{
				color: #FF1543;
			}
		}
		.list{
			margin-top: 20px;
			.item{
				border: 1px solid rgba(112,112,112,0.42);
				border-radius: 10px;
				display: flex;
				padding: 20upx;
				margin-top: 20px;
				justify-content: space-between;
				align-items: center;
				.head{
					width: 34px;
					height: 34px;
					image{
						width: 34px;
						height: 34px;
					}
				}
				.right{
					width: calc(100% - 44px);
					display: flex;
					justify-content: space-between;
					align-items: center;
					.box{
						.mobiles{
							font-size: 16px;
							font-family: Source Han Sans SC, Source Han Sans SC-Bold;
							font-weight: 700;
							text-align: left;
							color: #000000;
							line-height: 21px;
							letter-spacing: 0.32px;
							margin-bottom: 5px;
						}
						text{
							font-size: 10px;
							font-family: Source Han Sans SC, Source Han Sans SC-Regular;
							font-weight: 400;
							text-align: left;
							line-height: 21px;
							letter-spacing: 0.2px;
							color: #01D10F;
							background: #D9F8DB;
							border-radius: 4px;
							padding: 1px 2px;
						}
					}
				}
			}
		}
	}
</style>
